package com.wontube.smr.dao.mapper;


import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.session.RowBounds;

import com.wontube.core.dao.mybatis.QueryExample;
import com.wontube.smr.client.model.po.TVShow;
import com.wontube.smr.dao.providers.TVShowSqlProvider;


public interface TVShowMapper {

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table tv_show
	 * @mbggenerated
	 */
	int countByExample(QueryExample example);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table tv_show
	 * @mbggenerated
	 */
	int deleteByExample(QueryExample example);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table tv_show
	 * @mbggenerated
	 */
	int deleteByPrimaryKey(String id);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table tv_show
	 * @mbggenerated
	 */
	int insert(TVShow record);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table tv_show
	 * @mbggenerated
	 */
	int insertSelective(TVShow record);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table tv_show
	 * @mbggenerated
	 */
	List<TVShow> selectByExample(QueryExample example, RowBounds rowBounds);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table tv_show
	 * @mbggenerated
	 */
	List<TVShow> selectByExample(QueryExample example);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table tv_show
	 * @mbggenerated
	 */
	TVShow selectByPrimaryKey(String id);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table tv_show
	 * @mbggenerated
	 */
	int updateByExampleSelective(@Param("record") TVShow record,
			@Param("example") QueryExample example);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table tv_show
	 * @mbggenerated
	 */
	int updateByExample(@Param("record") TVShow record,
			@Param("example") QueryExample example);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table tv_show
	 * @mbggenerated
	 */
	int updateByPrimaryKeySelective(TVShow record);

	/**
	 * This method was generated by MyBatis Generator. This method corresponds to the database table tv_show
	 * @mbggenerated
	 */
	int updateByPrimaryKey(TVShow record);

	// user defined
	@SelectProvider(type=TVShowSqlProvider.class, method="countWithRecent")
	int countWithRecent(QueryExample example);
	
	@SelectProvider(type=TVShowSqlProvider.class, method="selectWithRecent")
	@ResultMap("BaseResultMap")
	List<TVShow> selectWithRecent(QueryExample example, RowBounds rowBounds);
	
	@SelectProvider(type=TVShowSqlProvider.class, method="countWithToday")
	int countWithToday(QueryExample example);
	
	@SelectProvider(type=TVShowSqlProvider.class, method="selectWithToday")
	@ResultMap("BaseResultMap")
	List<TVShow> selectWithToday(QueryExample example, RowBounds rowBounds);
	
	@SelectProvider(type=TVShowSqlProvider.class, method="countWithByGenre")
	int countWithByGenre(@Param("genreName")String genreName, @Param("example")QueryExample example);
	
	@SelectProvider(type=TVShowSqlProvider.class, method="selectWithByGenre")
	@ResultMap("BaseResultMap")
	List<TVShow> selectWithByGenre(@Param("genreName")String genreName, @Param("example")QueryExample example, RowBounds rowBounds);

	@SelectProvider(type=TVShowSqlProvider.class, method="countWithRecentByGenre")
	int countWithRecentByGenre(@Param("genreName")String genreName, @Param("example")QueryExample example);
	
	@SelectProvider(type=TVShowSqlProvider.class, method="selectWithRecentByGenre")
	@ResultMap("BaseResultMap")
	List<TVShow> selectWithRecentByGenre(@Param("genreName")String genreName, @Param("example")QueryExample example, RowBounds rowBounds);
	
	@SelectProvider(type=TVShowSqlProvider.class, method="selectWithDramaByGenre")
	@ResultMap("BaseResultMap")
	List<TVShow> selectWithDramaByGenre(@Param("genreName")String genreName, @Param("example")QueryExample example, RowBounds rowBounds);
	
	@Update({ "update tv_show", 
		"set sort_index = sort_index + #{added,jdbcType=INTEGER}", 
		"where version < #{maxOldVersion,jdbcType=TIMESTAMP}",
		"and website = #{website,jdbcType=VARCHAR}",
		"and sort_index < #{maxOldIndex,jdbcType=INTEGER}"})
	int updateOldSortIndex(String website, Date maxOldVersion, int added, int maxOldIndex);
	
	@Update({ "update tv_show set genre=#{genre,jdbcType=VARCHAR} where id=#{showId,jdbcType=VARCHAR}"})
	int updateGenre(@Param("showId") String showId, @Param("genre") String genre);
	
	@Update({ "update tv_show set category=#{category,jdbcType=VARCHAR} where id=#{showId,jdbcType=VARCHAR}"})
	int updateCategory(@Param("showId") String showId, @Param("category")String category);
	
	@Update({ "update tv_show set sort_index=#{sortIndex, jdbcType=INTEGER}, version=#{version,jdbcType=TIMESTAMP} where id=#{showId,jdbcType=VARCHAR}"})
	int updateSortIndex(@Param("showId") String showId, @Param("sortIndex") Integer sortIndex, @Param("version") Date version);
}